package fr.labri.harmony.analysis.jsep.results.filter;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import fr.labri.harmony.analysis.jsep.results.LoadRules;

public class MigrationFiles extends ResultFilter {

	@Override
	public void computeResult(ResultSet rs) throws SQLException, IOException {
		rs.first();
		List<Integer> correct_distance_nb_fichiers = new ArrayList<Integer>();
		List<Integer> wrong_distance_nb_fichiers = new ArrayList<Integer>();

		while (rs.next()){			
			String source = rs.getString("NAME");
			String target = rs.getString("MIGRATION_LIB_TO");
			if(target!=null) {
				int nb1 = rs.getInt("migration_nb_fichiers_in");
				int nb2 = rs.getInt("migration_nb_fichiers_out");
				if(LoadRules.isTrueRule(source, target)) {
					correct_distance_nb_fichiers.add(Math.abs(nb2-nb1));
				}
				else {
					wrong_distance_nb_fichiers.add(Math.abs(nb2-nb1));
				}
			}
		}

		displayList("Files ",correct_distance_nb_fichiers, wrong_distance_nb_fichiers);
	}

}
